<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        window.onload = function() {
            var user = document.getElementById('user');
            var username = user.value;
            var pwd = document.getElementById('pwd').value;
            user.onblur = function() {
                var xhr = null;
                if (window.XMLHttpRequest) {
                    xhr = new XMLHttpRequest()
                } else {
                    xhr = new ActiveXObject("Microsoft.XMLHTTP");
                }
                var parm = "username" + usernmae + "$password=" + pwd;
                xhr.open('get', './test.php?' + encodeURI(parm));

                xhr.send(null);

                xhr.onredystatechange = function() {
                    if (xhr.readyState == 4) {
                        if (xhr.status == 200) {
                            var span = document.getElementById('info')
                            sapn.innerHTML = xhr.responseText;
                        }
                    }
                }
            }
        }
    </script>
</head>

<body>
    <form action="">
        用户名:<input type="text" name="username" id="user">
        <span id="info"></span><br>密码:
        <input type="text" id="pwd">
        <input type="button" value="注册" id="btn">
    </form>
</body>

</html>